﻿using Interface.Cache;
using Interface.Core.Controllers;
using Interface.Core.Utility;
using Interface.Mvc.Areas.Scrm.Models;
using Interface.Redis;
using Interface.Utility.Helper;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Interface.Mvc.Areas.Scrm.Controllers
{
    public class AppController : CoreController
    {
        /// <summary>
        /// app登录
        /// url: /scrm/app/mobilelogin
        /// </summary>
        [HttpPost]
        public string mobilelogin(string phone, string password, string versioninfo, string machinecode, string phonemodel)
        {
            var re = db.Crm.StoredQuery<dynamic>("MB_Sp_MobileLogin", new
            {
                phone,
                password,
                versioninfo,
                machinecode,
                phonemodel
            }).FirstOrDefault();

            return ResultUtility.UnknownResult(re.success, re.imessage, re.imessage, data: re);
        }

        /// <summary>
        /// 权限列表
        /// url: /scrm/app/limitslist
        /// </summary>
        [HttpGet]
        public string limitslist(int userid, int irole, string code, string name, int id, int ywdwid, int cityid)
        {
            List<dynamic> list = db.Crm.StoredQuery<dynamic>("Mb_Sp_LimitsList", new
            {
                userid,
                irole,
                code,
                name,
                id,
                ywdwid,
                cityid
            }).ToList();

            return ResultUtility.SuccessResult(data: list);
        }

        /// <summary>
        /// 盘点单列表
        /// url: /scrm/app/inventorylist
        /// </summary>
        [HttpGet]
        public string inventorylist(int userid, int irole)
        {
            List<dynamic> list = db.Crm.StoredQuery<dynamic>("Mb_Sp_InventoryList", new
            {
                userid,
                irole
            }).ToList();

            return ResultUtility.SuccessResult(data: list);
        }

        /// <summary>
        /// 盘点单列表
        /// url: /scrm/app/inventorylistnew
        /// </summary>
        [HttpGet]
        public string inventorylistnew(int userid, int irole, int beginid)
        {
            List<dynamic> list = db.Crm.StoredQuery<dynamic>("Mb_Sp_InventoryListNew", new
            {
                userid,
                irole,
                beginid
            }).ToList();

            return ResultUtility.SuccessResult(data: list);
        }

        /// <summary>
        /// 提交盘点
        /// url: /scrm/app/submitinventory
        /// </summary>
        [HttpPost]
        public string submitinventory(int userid, int irole, int keyid)
        {
            ResultEntity re = db.Crm.StoredQuery<ResultEntity>("Mb_Sp_SubmitInventory", new
            {
                userid,
                irole,
                keyid
            }).FirstOrDefault();

            return ResultUtility.UnknownResult(re.success, re.imessage, re.imessage, re.data);
        }

        /// <summary>
        /// 获取产品信息
        /// url: /scrm/app/wlminfo
        /// </summary>
        [HttpPost]
        public string wlminfo(string code_wl)
        {
            var re = db.Crm.StoredQuery<dynamic>("Mb_Sp_WlmInfo", new
            {
                code_wl
            }).FirstOrDefault();

            return ResultUtility.UnknownResult(re.success, re.imessage, re.imessage, data: re);
        }

        /// <summary>
        /// 更新盘点单据状态
        /// url: /scrm/app/setinventorystatus
        /// </summary>
        [HttpPost]
        public string setinventorystatus(string code)
        {
            db.Crm.Execute("update Mb_Inventory set IStatus = '已完成' where code = @code", new { code = code });
            return ResultUtility.SuccessResult();
        }

        /// <summary>
        /// 提交盘点物流码
        /// url: /scrm/app/submitinventorywlm
        /// </summary>
        [HttpPost]
        public string submitinventorywlm(int userid, int irole, string code, string code_wl, string cpname, string picturename, string picturepath, int itype)
        {
            ResultEntity re = db.Crm.StoredQuery<ResultEntity>("Mb_Sp_SubmitInventoryWlm", new
            {
                userid,
                irole,
                code,
                code_wl,
                cpname,
                picturename,
                picturepath,
                itype
            }).FirstOrDefault();

            return ResultUtility.UnknownResult(re.success, re.imessage, re.imessage, re.data);
        }

        /// <summary>
        /// 获取盘点汇总数据
        /// url: /scrm/app/inventorysum
        /// </summary>
        [HttpGet]
        public string inventorysum(string code)
        {
            List<dynamic> list = db.Crm.StoredQuery<dynamic>("Mb_Sp_InventorySum", new
            {
                code
            }).ToList();

            return ResultUtility.SuccessResult(data: list);
        }

        /// <summary>
        /// 获取盘点明细数据
        /// url: /scrm/app/inventorydtl
        /// </summary>
        [HttpGet]
        public string inventorydtl(string code)
        {
            List<dynamic> list = db.Crm.StoredQuery<dynamic>("Mb_Sp_InventoryDtl", new
            {
                code
            }).ToList();

            return ResultUtility.SuccessResult(data: list);
        }

        /// <summary>
        /// 删除盘点明细数据
        /// url: /scrm/app/deleteinventory
        /// </summary>
        [HttpPost]
        public string deleteinventory(int keyid)
        {
            db.Crm.Execute("delete from Mb_InventoryDtl where Keyid = @keyid", new { keyid = keyid });
            return ResultUtility.SuccessResult();
        }

        /// <summary>
        /// 生成导购引流二维码
        /// url: /scrm/app/getqrcode
        /// </summary>
        [HttpGet]
        public string getqrcode()
        {
            int rd = new Random().Next(999999);
            // 2016 年第 36 周开的内容，前缀 1636 为导购注册导流专用前缀
            string sceneId = "1636" + rd.ToString().PadLeft(6, '0');

            Dictionary<string, object> dic = new Dictionary<string, object>();

            // 有效时间暂定 20 分钟
            dic.Add("expireSeconds", 1200);
            dic.Add("sceneId", sceneId);

            var json = HttpHelper.Get("https://www.uvmami.com/interface/getqrcode?key=engnice", dic);

            var result = JsonHelper.Deserialize<dynamic>(json);

            string id = result.Ticket, errmsg = result.Remark;

            if (!string.IsNullOrEmpty(id))
            {
                Hashtable hash = new Hashtable();

                hash["status"] = "wait";

                CommonRedis.SetValue<Hashtable>("AppGuideQrCode_" + sceneId, hash, 20);

                string url = "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket={0}";

                return ResultUtility.SuccessResult(data: new { url = string.Format(url, id), sceneid = sceneId });
            }
            else { return ResultUtility.FailureResult(errmsg); }
        }

        /// <summary>
        /// 根据二维码标识读取信息
        /// url: /scrm/app/getqrcoderesult
        /// </summary>
        [HttpGet]
        public string getqrcoderesult(int sceneid)
        {
            Hashtable hash = null;

            for (int i = 0; i < 50; i++)
            {
                hash = CommonRedis.GetValue<Hashtable>("AppGuideQrCode_" + sceneid);

                if (hash != null)
                {
                    if (hash["status"].Equals("complete"))
                    {
                        var result = new { status = "complete", openid = hash["openid"] };
                        CommonRedis.RemoveKey("AppGuideQrCode_" + sceneid);
                        return ResultUtility.SuccessResult(data: result);
                    }
                }
                else { return ResultUtility.FailureResult("失效的二维码"); }

                System.Threading.Thread.Sleep(500);
            }

            return ResultUtility.SuccessResult(data: new { status = "wait", openid = string.Empty });
        }

        /// <summary>
        /// 设置二维码状态
        /// url: /scrm/app/setqrcoderesult
        /// </summary>
        [HttpGet]
        public string setqrcoderesult(int sceneid, string openid)
        {
            var hash = CommonRedis.GetValue<Hashtable>("AppGuideQrCode_" + sceneid);

            if (hash != null)
            {
                hash["status"] = "complete"; hash["openid"] = openid;

                CommonRedis.SetValue<Hashtable>("AppGuideQrCode_" + sceneid, hash);

                return ResultUtility.SuccessResult();
            }

            return ResultUtility.FailureResult(); ;
        }

        /// <summary>
        /// 通过手机号码获取会员信息
        /// url: /scrm/app/mobilegetinfo
        /// </summary>
        [HttpGet]
        public string mobilegetinfo(string mobile)
        {
            List<dynamic> list = db.Crm.StoredQuery<dynamic>("MB_Sp_MobileGetInfo", new
            {
                mobile
            }).ToList();

            return ResultUtility.SuccessResult(data: list);
        }

        /// <summary>
        /// 会员注册
        /// url: /scrm/app/mobileregister  
        /// </summary>
        [HttpPost]
        public string mobileregister(int userid, int irole, string wxid, string mobile, string name, string code, string birthday, 
            string sex, string province, string city, string region, string iaddress, string codes)
        {
            ResultEntity re = db.Crm.StoredQuery<ResultEntity>("MB_Sp_MobileRegister", new
            {
                userid,
                irole,
                wxid,
                mobile,
                name,
                code,
                birthday,
                sex,
                province,
                city,
                region,
                iaddress,
                codes
            }).FirstOrDefault();

            return ResultUtility.UnknownResult(re.success, re.imessage, re.imessage, re.data);
        }

        /// <summary>
        /// 通过手机号码获取会员简单信息
        /// url: /scrm/app/mobilegetsimpleinfo
        /// </summary>
        [HttpGet]
        public string mobilegetsimpleinfo(string mobile)
        {
            List<dynamic> list = db.Crm.StoredQuery<dynamic>("MB_Sp_MobileGetSimpleInfo", new
            {
                mobile
            }).ToList();

            return ResultUtility.SuccessResult(data: list);
        }

        /// <summary>
        /// 选择活动
        /// url: /scrm/app/memberactivities
        /// </summary>
        [HttpPost]
        public string memberactivities(string mobile, string mdcode)
        {
            var re = db.Crm.StoredQuery<dynamic>("Mb_Sp_MemberActivities", new
            {
                mobile,
                mdcode
            });

            if (re.Count() > 0)
            {
                var first = re.FirstOrDefault();

                return ResultUtility.UnknownResult(first.success > 0, first.imessage, first.imessage, data: re);
            }

            return ResultUtility.FailureResult("没有返回数据");
        }

        /// <summary>
        /// 积分
        /// url: /scrm/app/memberintegration
        /// </summary>
        [HttpPost]
        public string memberintegration(int userid, int irole, string mobile, string mdcode, string markcode, int activityid)
        {
            var re = db.Crm.StoredQuery<dynamic>("Mb_Sp_MemberIntegration", new
            {
                userid,
                irole,
                mobile,
                mdcode,
                markcode,
                activityid
            });

            if (re.Count() > 0)
            {
                var first = re.FirstOrDefault();

                return ResultUtility.UnknownResult(first.success, first.imessage, first.imessage, data: re);
            }

            return ResultUtility.FailureResult("没有返回数据");
        }

        /// <summary>
        /// 会员查询
        /// url: /scrm/app/membersearch
        /// </summary>
        [HttpGet]
        public string membersearch(int userid, int irole, string mobile, int bpoints, int epoints, string bdate, string edate, int beginid)
        {
            List<dynamic> list = db.Crm.StoredQuery<dynamic>("Mb_Sp_MemberSearch", new
            {
                userid,
                irole,
                mobile,
                bpoints,
                epoints,
                bdate,
                edate,
                beginid
            }).ToList();

            return ResultUtility.SuccessResult(data: list);
        }

        /// <summary>
        /// 通过crmid获取会员信息
        /// url: /scrm/app/crmidgetinfo
        /// </summary>
        [HttpGet]
        public string crmidgetinfo(int crmid)
        {
            List<dynamic> list = db.Crm.StoredQuery<dynamic>("MB_Sp_CrmidGetInfo", new
            {
                crmid
            }).ToList();

            return ResultUtility.SuccessResult(data: list);
        }

        /// <summary>
        /// 通过crmid获取查看更多 查看会员积分记录,兑换积分等
        /// url: /scrm/app/crmidgetdtlinfo
        /// </summary>
        [HttpGet]
        public string crmidgetdtlinfo(int crmid)
        {
            List<dynamic> list = db.Crm.StoredQuery<dynamic>("MB_Sp_CrmidGetDtlInfo", new
            {
                crmid
            }).ToList();

            return ResultUtility.SuccessResult(data: list);
        }

        /// <summary>
        /// 兑换类别
        /// url: /scrm/app/mobilegifttype
        /// </summary>
        [HttpGet]
        public string mobilegifttype()
        {
            List<dynamic> list = db.Crm.StoredQuery<dynamic>("MB_Sp_MobileGiftType", new
            {
            }).ToList();

            return ResultUtility.SuccessResult(data: list);
        }

        /// <summary>
        /// 兑换列表
        /// url: /scrm/app/mobilegiftlist
        /// </summary>
        [HttpGet]
        public string mobilegiftlist(int page)
        {
            List<dynamic> list = db.Crm.StoredQuery<dynamic>("MB_Sp_MobileGiftList", new
            {
                page
            }).ToList();

            return ResultUtility.SuccessResult(data: list);
        }

        /// <summary>
        /// 兑换
        /// url: /scrm/app/mobilebuygift
        /// </summary>
        [HttpPost]
        public string mobilebuygift(int userid, int irole, string id, string count, string shop, string verify, string phone, string markcode)
        {
            ResultEntity re = db.Crm.StoredQuery<ResultEntity>("MB_Sp_MobileBuyGift", new
            {
                userid,
                irole,
                id,
                count,
                shop,
                verify,
                phone,
                markcode
            }).FirstOrDefault();

            return ResultUtility.UnknownResult(re.success, re.imessage, re.imessage, re.data);
        }

        /// <summary>
        /// 发货单列表
        /// url: /scrm/app/fhlist
        /// </summary>
        [HttpGet]
        public string fhlist(int userid, int irole, int beginid)
        {
            List<dynamic> list = db.Crm.StoredQuery<dynamic>("Mb_Sp_FHList", new
            {
                userid,
                irole,
                beginid
            }).ToList();

            return ResultUtility.SuccessResult(data: list);
        }

        /// <summary>
        /// 开始发货
        /// url: /scrm/app/submitfh
        /// </summary>
        [HttpPost]
        public string submitfh(int userid, int irole, int keyid, string remarks)
        {
            ResultEntity re = db.Crm.StoredQuery<ResultEntity>("Mb_Sp_SubmitFH", new
            {
                userid,
                irole,
                keyid,
                remarks
            }).FirstOrDefault();

            return ResultUtility.UnknownResult(re.success, re.imessage, re.imessage, re.data);
        }

        /// <summary>
        /// 发货
        /// url: /scrm/app/submitfhwlm
        /// </summary>
        [HttpPost]
        public string submitfhwlm(int userid, int irole, string code, string code_wl, string commonlanguage)
        {
            ResultEntity re = db.Crm.StoredQuery<ResultEntity>("Mb_Sp_SubmitFHWlm", new
            {
                userid,
                irole,
                code,
                code_wl,
                commonlanguage
            }).FirstOrDefault();

            return ResultUtility.UnknownResult(re.success, re.imessage, re.imessage, re.data);
        }

        /// <summary>
        /// 获取发货汇总数据
        /// url: /scrm/app/fhsum
        /// </summary>
        [HttpGet]
        public string fhsum(string code)
        {
            List<dynamic> list = db.Crm.StoredQuery<dynamic>("Mb_Sp_FHSum", new
            {
                code
            }).ToList();

            return ResultUtility.SuccessResult(data: list);
        }

        /// <summary>
        /// 获取发货明细数据
        /// url: /scrm/app/fhdtl
        /// </summary>
        [HttpGet]
        public string fhdtl(string code)
        {
            List<dynamic> list = db.Crm.StoredQuery<dynamic>("Mb_Sp_FHDtl", new
            {
                code
            }).ToList();

            return ResultUtility.SuccessResult(data: list);
        }

        /// <summary>
        /// 获取常用语
        /// url: /scrm/app/commonlanguage
        /// </summary>
        [HttpGet]
        public string commonlanguage(int userid, int irole)
        {
            List<dynamic> list = db.Crm.StoredQuery<dynamic>("Mb_Sp_CommonLanguage", new
            {
                userid,
                irole
            }).ToList();

            return ResultUtility.SuccessResult(data: list);
        }

        /// <summary>
        /// 新增常用语
        /// url: /scrm/app/insertcommonlanguage
        /// </summary>
        [HttpPost]
        public string insertcommonlanguage(int userid, int irole, string commonlanguage)
        {
            db.Crm.Execute("Insert into Mb_CommonLanguage(UserId,Irole,CommonLanguage) Select @userid,@irole,@commonlanguage", new { userid = userid, irole = irole, commonlanguage = commonlanguage });
            return ResultUtility.SuccessResult();
        }

        /// <summary>
        /// 删除常用语
        /// url: /scrm/app/deletecommonlanguage
        /// </summary>
        [HttpPost]
        public string deletecommonlanguage(int keyid)
        {
            db.Crm.Execute("delete from Mb_CommonLanguage where Keyid = @keyid", new { keyid = keyid });
            return ResultUtility.SuccessResult();
        }

        /// <summary>
        /// 更新发货单据状态
        /// url: /scrm/app/setfhstatus
        /// </summary>
        [HttpPost]
        public string setfhstatus(string code)
        {
            db.Crm.Execute("update Mb_FH set IStatus = '已完成' where code = @code", new { code = code });
            return ResultUtility.SuccessResult();
        }

        /// <summary>
        /// 退货单列表
        /// url: /scrm/app/thlist
        /// </summary>
        [HttpGet]
        public string thlist(int userid, int irole, int beginid)
        {
            List<dynamic> list = db.Crm.StoredQuery<dynamic>("Mb_Sp_THList", new
            {
                userid,
                irole,
                beginid
            }).ToList();

            return ResultUtility.SuccessResult(data: list);
        }

        /// <summary>
        /// 开始退货
        /// url: /scrm/app/submitth
        /// </summary>
        [HttpPost]
        public string submitth(int userid, int irole, string remarks)
        {
            ResultEntity re = db.Crm.StoredQuery<ResultEntity>("Mb_Sp_SubmitTH", new
            {
                userid,
                irole,
                remarks
            }).FirstOrDefault();

            return ResultUtility.UnknownResult(re.success, re.imessage, re.imessage, re.data);
        }

        /// <summary>
        /// 退货
        /// url: /scrm/app/submitthwlm
        /// </summary>
        [HttpPost]
        public string submitthwlm(int userid, int irole, string code, string code_wl, string commonlanguage)
        {
            ResultEntity re = db.Crm.StoredQuery<ResultEntity>("Mb_Sp_SubmitTHWlm", new
            {
                userid,
                irole,
                code,
                code_wl,
                commonlanguage
            }).FirstOrDefault();

            return ResultUtility.UnknownResult(re.success, re.imessage, re.imessage, re.data);
        }

        /// <summary>
        /// 获取退货汇总数据
        /// url: /scrm/app/thsum
        /// </summary>
        [HttpGet]
        public string thsum(string code)
        {
            List<dynamic> list = db.Crm.StoredQuery<dynamic>("Mb_Sp_THSum", new
            {
                code
            }).ToList();

            return ResultUtility.SuccessResult(data: list);
        }

        /// <summary>
        /// 获取退货明细数据
        /// url: /scrm/app/thdtl
        /// </summary>
        [HttpGet]
        public string thdtl(string code)
        {
            List<dynamic> list = db.Crm.StoredQuery<dynamic>("Mb_Sp_THDtl", new
            {
                code
            }).ToList();

            return ResultUtility.SuccessResult(data: list);
        }

        /// <summary>
        /// 更新退货单据状态
        /// url: /scrm/app/setthstatus
        /// </summary>
        [HttpPost]
        public string setthstatus(string code)
        {
            db.Crm.Execute("update Mb_TH set IStatus = '已完成' where code = @code", new { code = code });
            return ResultUtility.SuccessResult();
        }

        /// <summary>
        /// 收货单列表
        /// url: /scrm/app/shlist
        /// </summary>
        [HttpGet]
        public string shlist(int userid, int irole, int beginid)
        {
            List<dynamic> list = db.Crm.StoredQuery<dynamic>("Mb_Sp_SHList", new
            {
                userid,
                irole,
                beginid
            }).ToList();

            return ResultUtility.SuccessResult(data: list);
        }

        /// <summary>
        /// 开始收货
        /// url: /scrm/app/submitsh
        /// </summary>
        [HttpPost]
        public string submitsh(int userid, int irole, int keyid, string remarks)
        {
            ResultEntity re = db.Crm.StoredQuery<ResultEntity>("Mb_Sp_SubmitSH", new
            {
                userid,
                irole,
                keyid,
                remarks
            }).FirstOrDefault();

            return ResultUtility.UnknownResult(re.success, re.imessage, re.imessage, re.data);
        }

        /// <summary>
        /// 收货
        /// url: /scrm/app/submitshwlm
        /// </summary>
        [HttpPost]
        public string submitshwlm(int userid, int irole, string code, string code_wl, string commonlanguage)
        {
            ResultEntity re = db.Crm.StoredQuery<ResultEntity>("Mb_Sp_SubmitSHWlm", new
            {
                userid,
                irole,
                code,
                code_wl,
                commonlanguage
            }).FirstOrDefault();

            return ResultUtility.UnknownResult(re.success, re.imessage, re.imessage, re.data);
        }

        /// <summary>
        /// 获取收货汇总数据
        /// url: /scrm/app/shsum
        /// </summary>
        [HttpGet]
        public string shsum(string code)
        {
            List<dynamic> list = db.Crm.StoredQuery<dynamic>("Mb_Sp_SHSum", new
            {
                code
            }).ToList();

            return ResultUtility.SuccessResult(data: list);
        }

        /// <summary>
        /// 获取收货明细数据
        /// url: /scrm/app/shdtl
        /// </summary>
        [HttpGet]
        public string shdtl(string code)
        {
            List<dynamic> list = db.Crm.StoredQuery<dynamic>("Mb_Sp_SHDtl", new
            {
                code
            }).ToList();

            return ResultUtility.SuccessResult(data: list);
        }

        /// <summary>
        /// 更新收货单据状态
        /// url: /scrm/app/setshstatus
        /// </summary>
        [HttpPost]
        public string setshstatus(string code)
        {
            db.Crm.Execute("update Mb_SH set IStatus = '已完成' where code = @code", new { code = code });
            return ResultUtility.SuccessResult();
        }

        /// <summary>
        /// 正确积分码查询
        /// url: /scrm/app/correctjfm
        /// </summary>
        [HttpGet]
        public string correctjfm(int userid, int irole, int itype, string jfm, string reason)
        {
            List<dynamic> list = db.Crm.StoredQuery<dynamic>("Mb_sp_correctjfm", new
            {
                userid,
                irole,
                itype,
                jfm,
                reason
            }).ToList();

            return ResultUtility.SuccessResult(data: list);
        }

        /// <summary>
        /// 物流码查询
        /// url: /scrm/app/wlmsearch
        /// </summary>
        [HttpGet]
        public string wlmsearch(string mdcode, string wlm)
        {
            List<dynamic> list = db.Crm.StoredQuery<dynamic>("Mb_sp_wlmsearch", new
            {
                mdcode,
                wlm
            }).ToList();

            return ResultUtility.SuccessResult(data: list);
        }

        /// <summary>
        /// 门店经销商兑换类别
        /// url: /scrm/app/dhtype
        /// </summary>
        [HttpGet]
        public string dhtype()
        {
            List<dynamic> list = db.Crm.StoredQuery<dynamic>("MB_Sp_DHType", new
            {
            }).ToList();

            return ResultUtility.SuccessResult(data: list);
        }

        /// <summary>
        /// 门店经销商兑换列表
        /// url: /scrm/app/hyddhproducts
        /// </summary>
        [HttpGet]
        public string hyddhproducts(int userid, int irole, int page)
        {
            List<dynamic> list = db.Crm.StoredQuery<dynamic>("Mb_sp_HYDDHProducts", new
            {
                userid,
                irole,
                page
            }).ToList();

            return ResultUtility.SuccessResult(data: list);
        }

        /// <summary>
        /// 门店经销商信息
        /// url: /scrm/app/dealerinfo
        /// </summary>
        [HttpGet]
        public string dealerinfo(int userid, int irole)
        {
            List<dynamic> list = db.Crm.StoredQuery<dynamic>("Mb_Sp_DealerInfo", new
            {
                userid,
                irole
            }).ToList();

            return ResultUtility.SuccessResult(data: list);
        }

        /// <summary>
        /// 门店兑换
        /// url: /scrm/app/hyddh
        /// </summary>
        [HttpPost]
        public string hyddh(int userid, int irole, string id, string count, string remark)
        {
            ResultEntity re = db.Crm.StoredQuery<ResultEntity>("MB_Sp_HYDDH", new
            {
                userid,
                irole,
                id,
                count,
                remark
            }).FirstOrDefault();

            return ResultUtility.UnknownResult(re.success, re.imessage, re.imessage, re.data);
        }

        /// <summary>
        /// 业务单位
        /// url: /scrm/app/ywdw
        /// </summary>
        [HttpGet]
        public string ywdw()
        {
            List<dynamic> list = db.Crm.StoredQuery<dynamic>("MB_Sp_YWDW", new
            {
            }).ToList();

            return ResultUtility.SuccessResult(data: list);
        }

        /// <summary>
        /// 业务单位下属经销商
        /// url: /scrm/app/ywdwjxs
        /// </summary>
        [HttpGet]
        public string ywdwjxs(int id)
        {
            List<dynamic> list = db.Crm.StoredQuery<dynamic>("MB_Sp_YWDWJXS", new
            {
                id
            }).ToList();

            return ResultUtility.SuccessResult(data: list);
        }

        /// <summary>
        /// 门店兑换查询
        /// url: /scrm/app/hyddhjlcx
        /// </summary>
        [HttpGet]
        public string hyddhjlcx(int userid, int irole, string bdate, string edate, string sname, string mdcode, int jxskeyid, string dhstatus)
        {
            List<dynamic> list = db.Crm.StoredQuery<dynamic>("MB_Sp_HYDDHJLSHPageNew", new
            {
                userid,
                irole,
                bdate,
                edate,
                sname,
                mdcode,
                jxskeyid,
                dhstatus
            }).ToList();

            return ResultUtility.SuccessResult(data: list);
        }

        /// <summary>
        /// 会员店兑换审核
        /// url: /scrm/app/hyddhjlsh
        /// </summary>
        [HttpPost]
        public string hyddhjlsh(int userid, int irole, string dhdcode)
        {
            ResultEntity re = db.Crm.StoredQuery<ResultEntity>("MB_sp_HYDDHJLSH", new
            {
                userid,
                irole,
                dhdcode
            }).FirstOrDefault();

            return ResultUtility.UnknownResult(re.success, re.imessage, re.imessage, re.data);
        }

        /// <summary>
        /// 会员店兑换配送
        /// url: /scrm/app/hyddhjlps
        /// </summary>
        [HttpPost]
        public string hyddhjlps(int userid, int irole, string dhdcode)
        {
            ResultEntity re = db.Crm.StoredQuery<ResultEntity>("MB_sp_HYDDHJLPS", new
            {
                userid,
                irole,
                dhdcode
            }).FirstOrDefault();

            return ResultUtility.UnknownResult(re.success, re.imessage, re.imessage, re.data);
        }

        /// <summary>
        /// 会员店兑换退回
        /// url: /scrm/app/hyddhjlth
        /// </summary>
        [HttpPost]
        public string hyddhjlth(int userid, int irole, string dhdcode)
        {
            ResultEntity re = db.Crm.StoredQuery<ResultEntity>("MB_sp_HYDDHJLTH", new
            {
                userid,
                irole,
                dhdcode
            }).FirstOrDefault();

            return ResultUtility.UnknownResult(re.success, re.imessage, re.imessage, re.data);
        }

        /// <summary>
        /// 会员店兑换删除
        /// url: /scrm/app/hyddhjlsc
        /// </summary>
        [HttpPost]
        public string hyddhjlsc(int userid, int irole, string dhdcode)
        {
            ResultEntity re = db.Crm.StoredQuery<ResultEntity>("MB_sp_HYDDHCX", new
            {
                userid,
                irole,
                dhdcode
            }).FirstOrDefault();

            return ResultUtility.UnknownResult(re.success, re.imessage, re.imessage, re.data);
        }

        /// <summary>
        /// 会员店确认收货
        /// url: /scrm/app/hyddhjlqrsh
        /// </summary>
        [HttpPost]
        public string hyddhjlqrsh(int userid, int irole, string dhdcode)
        {
            ResultEntity re = db.Crm.StoredQuery<ResultEntity>("MB_sp_HYDDHQRSH", new
            {
                userid,
                irole,
                dhdcode
            }).FirstOrDefault();

            return ResultUtility.UnknownResult(re.success, re.imessage, re.imessage, re.data);
        }

        /// <summary>
        /// 经销商兑换
        /// url: /scrm/app/jxsdh
        /// </summary>
        [HttpPost]
        public string jxsdh(int userid, int irole, string id, string count, string remark)
        {
            ResultEntity re = db.Crm.StoredQuery<ResultEntity>("MB_Sp_NewXPJXSDH", new
            {
                userid,
                irole,
                id,
                count,
                remark
            }).FirstOrDefault();

            return ResultUtility.UnknownResult(re.success, re.imessage, re.imessage, re.data);
        }

        /// <summary>
        /// 经销商兑换查询
        /// url: /scrm/app/jxsdhjlcx
        /// </summary>
        [HttpGet]
        public string jxsdhjlcx(int userid, int irole, string bdate, string edate, string sname, string mdcode, int jxskeyid, string dhstatus)
        {
            List<dynamic> list = db.Crm.StoredQuery<dynamic>("MB_Sp_JXSDHJLSHPageNew", new
            {
                userid,
                irole,
                bdate,
                edate,
                sname,
                mdcode,
                jxskeyid,
                dhstatus
            }).ToList();

            return ResultUtility.SuccessResult(data: list);
        }

        /// <summary>
        /// 经销商兑换审核
        /// url: /scrm/app/jxsdhjlsh
        /// </summary>
        [HttpPost]
        public string jxsdhjlsh(int userid, int irole, string dhdcode)
        {
            ResultEntity re = db.Crm.StoredQuery<ResultEntity>("MB_sp_JXSDHJLSH", new
            {
                userid,
                irole,
                dhdcode
            }).FirstOrDefault();

            return ResultUtility.UnknownResult(re.success, re.imessage, re.imessage, re.data);
        }

        /// <summary>
        /// 经销商兑换配送
        /// url: /scrm/app/jxsdhjlps
        /// </summary>
        [HttpPost]
        public string jxsdhjlps(int userid, int irole, string dhdcode)
        {
            ResultEntity re = db.Crm.StoredQuery<ResultEntity>("Mb_sp_JXSDHJLPS", new
            {
                userid,
                irole,
                dhdcode
            }).FirstOrDefault();

            return ResultUtility.UnknownResult(re.success, re.imessage, re.imessage, re.data);
        }

        /// <summary>
        /// 经销商兑换退回
        /// url: /scrm/app/jxsdhjlth
        /// </summary>
        [HttpPost]
        public string jxsdhjlth(int userid, int irole, string dhdcode)
        {
            ResultEntity re = db.Crm.StoredQuery<ResultEntity>("MB_sp_JXSDHJLTH", new
            {
                userid,
                irole,
                dhdcode
            }).FirstOrDefault();

            return ResultUtility.UnknownResult(re.success, re.imessage, re.imessage, re.data);
        }

        /// <summary>
        /// 经销商兑换删除
        /// url: /scrm/app/jxsdhjlsc
        /// </summary>
        [HttpPost]
        public string jxsdhjlsc(int userid, int irole, string dhdcode)
        {
            ResultEntity re = db.Crm.StoredQuery<ResultEntity>("MB_sp_HYDDHCX", new
            {
                userid,
                irole,
                dhdcode
            }).FirstOrDefault();

            return ResultUtility.UnknownResult(re.success, re.imessage, re.imessage, re.data);
        }

        /// <summary>
        /// 门店兑换权限
        /// url: /scrm/app/mddhqx
        /// </summary>
        [HttpGet]
        public string mddhqx(int userid, int irole)
        {
            List<dynamic> list = db.Crm.StoredQuery<dynamic>("Mb_Sp_MDDHQX", new
            {
                userid,
                irole
            }).ToList();

            return ResultUtility.SuccessResult(data: list);
        }

        /// <summary>
        /// 经销商兑换权限
        /// url: /scrm/app/jxsdhqx
        /// </summary>
        [HttpGet]
        public string jxsdhqx(int userid, int irole)
        {
            List<dynamic> list = db.Crm.StoredQuery<dynamic>("Mb_Sp_JXSDHQX", new
            {
                userid,
                irole
            }).ToList();

            return ResultUtility.SuccessResult(data: list);
        }

        /// <summary>
        /// 积分汇总
        /// url: /scrm/app/mdjfzypage
        /// </summary>
        [HttpGet]
        public string mdjfzypage(int userid, int irole)
        {
            List<dynamic> list = db.Crm.StoredQuery<dynamic>("Mb_Sp_MdJfZyPage", new
            {
                userid,
                irole
            }).ToList();

            return ResultUtility.SuccessResult(data: list);
        }

        /// <summary>
        /// 积分转出
        /// url: /scrm/app/mdjfzy
        /// </summary>
        [HttpPost]
        public string mdjfzy(int userid, int irole, string id, string count)
        {
            ResultEntity re = db.Crm.StoredQuery<ResultEntity>("Mb_Sp_MdJfZy", new
            {
                userid,
                irole,
                id,
                count
            }).FirstOrDefault();

            return ResultUtility.UnknownResult(re.success, re.imessage, re.imessage, re.data);
        }

        /// <summary>
        /// 根据userid,irole获取用户信息
        /// url: /scrm/app/userinfo
        /// </summary>
        [HttpGet]
        public string userinfo(int userid, int irole)
        {
            List<dynamic> list = db.Crm.StoredQuery<dynamic>("Mb_Sp_UserInfo", new
            {
                userid,
                irole
            }).ToList();

            return ResultUtility.SuccessResult(data: list);
        }

        /// <summary>
        /// 公司组织架构
        /// url: /scrm/app/departmentifo
        /// </summary>
        [HttpGet]
        public string departmentifo(int userid, int irole, string name, int id)
        {
            List<dynamic> list = db.Crm.StoredQuery<dynamic>("Mb_Sp_DepartmentIfo", new
            {
                userid,
                irole,
                name,
                id
            }).ToList();

            return ResultUtility.SuccessResult(data: list);
        }

        /// <summary>
        /// 公司组织架构含员工信息
        /// url: /scrm/app/departmentuserifo
        /// </summary>
        [HttpGet]
        public string departmentuserifo(int userid, int irole, string name, int id)
        {
            List<dynamic> list = db.Crm.StoredQuery<dynamic>("Mb_Sp_DepartmentUserIfo", new
            {
                userid,
                irole,
                name,
                id
            }).ToList();

            return ResultUtility.SuccessResult(data: list);
        }

        /// <summary>
        /// 经销商+门店用户信息
        /// url: /scrm/app/dealeruserifo
        /// </summary>
        [HttpGet]
        public string dealeruserifo(int userid, int irole, string code, string name, int itype, int city, int jxsid)
        {
            List<dynamic> list = db.Crm.StoredQuery<dynamic>("Mb_Sp_DealerUserIfo", new
            {
                userid,
                irole,
                code,
                name,
                itype,
                city,
                jxsid
            }).ToList();

            return ResultUtility.SuccessResult(data: list);
        }

        /// <summary>
        /// 导购用户信息
        /// url: /scrm/app/guideUserifo
        /// </summary>
        [HttpGet]
        public string guideUserifo(int userid, int irole, string mobile, string name, int id)
        {
            List<dynamic> list = db.Crm.StoredQuery<dynamic>("Mb_Sp_GuideUserIfo", new
            {
                userid,
                irole,
                mobile,
                name,
                id
            }).ToList();

            return ResultUtility.SuccessResult(data: list);
        }

        /// <summary>
        /// 业务单位
        /// url: /scrm/app/province
        /// </summary>
        [HttpGet]
        public string province(int parentid)
        {
            List<dynamic> list = db.Crm.StoredQuery<dynamic>("MB_Sp_Province", new
            {
            }).ToList();

            return ResultUtility.SuccessResult(data: list);
        }

        /// <summary>
        /// 市
        /// url: /scrm/app/city
        /// </summary>
        [HttpGet]
        public string city(int parentid)
        {
            List<dynamic> list = db.Crm.StoredQuery<dynamic>("MB_Sp_City", new
            {
                parentid,
            }).ToList();

            return ResultUtility.SuccessResult(data: list);
        }

        /// <summary>
        /// 业务单位+省+市
        /// url: /scrm/app/ywdwpc
        /// </summary>
        [HttpGet]
        public string ywdwpc(int userid, int irole)
        {
            List<dynamic> list = db.Crm.StoredQuery<dynamic>("Mb_Sp_YWDWPC", new
            {
                userid,
                irole
            }).ToList();

            return ResultUtility.SuccessResult(data: list);
        }

        /// <summary>
        /// 市下属经销商或门店
        /// url: /scrm/app/citydealer
        /// </summary>
        [HttpGet]
        public string citydealer(int userid, int irole, int city, int jxsid)
        {
            List<dynamic> list = db.Crm.StoredQuery<dynamic>("Mb_Sp_CityDealer", new
            {
                userid,
                irole,
                city,
                jxsid
            }).ToList();

            return ResultUtility.SuccessResult(data: list);
        }

        /// <summary>
        /// 修改密码
        /// url: /scrm/app/updatepassword
        /// </summary>
        [HttpPost]
        public string updatepassword(string phone, string password)
        {
            var re = db.Crm.StoredQuery<dynamic>("MB_Sp_UpdatePassword", new
            {
                phone,
                password
            }).FirstOrDefault();

            return ResultUtility.UnknownResult(re.success, re.imessage, re.imessage, data: re);
        }

        /// <summary>
        /// 获取账号对应手机号码
        /// url: /scrm/app/getphone
        /// </summary>
        [HttpGet]
        public string getphone(string phone)
        {
            List<dynamic> list = db.Crm.StoredQuery<dynamic>("MB_Sp_GetPhone", new
            {
                phone
            }).ToList();

            return ResultUtility.SuccessResult(data: list);
        }

        /// <summary>
        /// 条码信息
        /// url: /scrm/app/productinfo
        /// </summary>
        [HttpGet]
        public string productinfo()
        {
            List<dynamic> list = db.Crm.StoredQuery<dynamic>("MB_Sp_ProductInfo", new
            {
            }).ToList();

            return ResultUtility.SuccessResult(data: list);
        }

        /// <summary>
        /// 获取最近条码统计信息
        /// url: /scrm/app/barcodeInfo
        /// </summary>
        [HttpGet]
        public string barcodeInfo(int userid, int irole, string code)
        {
            List<dynamic> list = db.Crm.StoredQuery<dynamic>("Mb_Sp_barcodeInfo", new
            {
                userid,
                irole,
                code
            }).ToList();

            return ResultUtility.SuccessResult(data: list);
        }

        /// <summary>
        /// 条码提交
        /// url: /scrm/app/submitbarcodeinfo
        /// </summary>
        [HttpPost]
        public string submitbarcodeinfo(int userid, int irole, int keyid, string usecode, string name, string id, int itype, string code)
        {
            ResultEntity re = db.Crm.StoredQuery<ResultEntity>("Mb_Sp_SubmitbarcodeInfo", new
            {
                userid,
                irole,
                keyid,
                usecode,
                name,
                id,
                itype,
                code
            }).FirstOrDefault();

            return ResultUtility.UnknownResult(re.success, re.imessage, re.imessage, re.data);
        }

        /// <summary>
        /// 获取当前单据条码统计信息
        /// url: /scrm/app/codebarcodeInfo
        /// </summary>
        [HttpGet]
        public string codebarcodeInfo(int userid, int irole, string code)
        {
            List<dynamic> list = db.Crm.StoredQuery<dynamic>("Mb_Sp_CodebarcodeInfo", new
            {
                userid,
                irole,
                code
            }).ToList();

            return ResultUtility.SuccessResult(data: list);
        }

        /// <summary>
        /// 更新条码单据状态
        /// url: /scrm/app/setbarcodestatus
        /// params: code
        /// </summary>
        [HttpPost]
        public string setbarcodestatus(string code)
        {
            db.Crm.Execute("update Mb_ProductInfo set IStatus = '已完成' where code = @code", new { code = code });
            return ResultUtility.SuccessResult();
        }

        /// <summary>
        /// 通过编号获取门店经销商信息
        /// url: /scrm/app/codedealerinfo
        /// </summary>
        [HttpGet]
        public string codedealerinfo(string code)
        {
            List<dynamic> list = db.Crm.StoredQuery<dynamic>("Mb_Sp_CodeDealerInfo", new
            {
                code
            }).ToList();

            return ResultUtility.SuccessResult(data: list);
        }

        /// <summary>
        /// 门店经销商信息提交
        /// url: /scrm/app/submitdealerinfo
        /// </summary>
        [HttpPost]
        public string submitdealerinfo(int userid, int irole, int keyid, string usecode, string name, string iaddress, bool milk, bool food,
            bool articles, string contact, string phone, decimal lat, decimal lng, string remarks, string area)
        {
            ResultEntity re = db.Crm.StoredQuery<ResultEntity>("Mb_Sp_SubmitDealerInfo", new
            {
                userid,
                irole,
                keyid,
                usecode,
                name,
                iaddress,
                milk,
                food,
                articles,
                contact,
                phone,
                lat,
                lng,
                remarks,
                area
            }).FirstOrDefault();

            return ResultUtility.UnknownResult(re.success, re.imessage, re.imessage, re.data);
        }

        /// <summary>
        /// 条码列表
        /// url: /scrm/app/barcodelist
        /// </summary>
        [HttpGet]
        public string barcodelist(int userid, int irole, int beginid, string usecode)
        {
            List<dynamic> list = db.Crm.StoredQuery<dynamic>("Mb_Sp_BarcodeList", new
            {
                userid,
                irole,
                beginid,
                usecode
            }).ToList();

            return ResultUtility.SuccessResult(data: list);
        }

        /// <summary>
        /// 签到签退
        /// url: /scrm/app/attendance
        /// </summary>
        [HttpPost]
        public string attendance(int userid, int irole, int itype, string addressstr, decimal lat, decimal lng, string picturename, string picturepath)
        {
            ResultEntity re = db.Crm.StoredQuery<ResultEntity>("Mb_Sp_Attendance", new
            {
                userid,
                irole,
                itype,
                addressstr,
                lat,
                lng,
                picturename,
                picturepath
            }).FirstOrDefault();
            
            return ResultUtility.UnknownResult(re.success, re.imessage, re.imessage, re.data);
        }

        /// <summary>
        /// 今日签到列表
        /// url: /scrm/app/attendancelist
        /// </summary>
        [HttpGet]
        public string attendancelist(int userid, int irole)
        {
            List<dynamic> list = db.Crm.StoredQuery<dynamic>("Mb_Sp_AttendanceList", new
            {
                userid,
                irole
            }).ToList();

            return ResultUtility.SuccessResult(data: list);
        }

        /// <summary>
        /// 完善信息审核列表
        /// url: /scrm/app/infolist
        /// </summary>
        [HttpGet]
        public string infolist(int userid, int irole)
        {
            List<dynamic> list = db.Crm.StoredQuery<dynamic>("Mb_Sp_InfoList", new
            {
                userid,
                irole
            }).ToList();

            return ResultUtility.SuccessResult(data: list);
        }

        /// <summary>
        /// 完善信息审核
        /// url: /scrm/app/infoaudit
        /// </summary>
        [HttpPost]
        public string infoaudit(int userid, int irole, string code)
        {
            ResultEntity re = db.Crm.StoredQuery<ResultEntity>("Mb_Sp_InfoAudit", new
            {
                userid,
                irole,
                code
            }).FirstOrDefault();

            return ResultUtility.UnknownResult(re.success, re.imessage, re.imessage, re.data);
        }

        /// <summary>
        /// 完善信息退回
        /// url: /scrm/app/inforeturn=
        /// </summary>
        [HttpPost]
        public string inforeturn(int userid, int irole, string code)
        {
            ResultEntity re = db.Crm.StoredQuery<ResultEntity>("Mb_Sp_InfoReturn", new
            {
                userid,
                irole,
                code
            }).FirstOrDefault();

            return ResultUtility.UnknownResult(re.success, re.imessage, re.imessage, re.data);
        }

        /// <summary>
        /// 考勤提醒
        /// url: /scrm/app/remind
        /// </summary>
        [HttpGet]
        public string remind(int userid, int irole)
        {
            List<dynamic> list = db.Crm.StoredQuery<dynamic>("Mb_Sp_Remind", new
            {
                userid,
                irole
            }).ToList();

            return ResultUtility.SuccessResult(data: list);
        }

        /// <summary>
        /// 考勤提醒保存
        /// url: /scrm/app/remindsave
        /// </summary>
        [HttpPost]
        public string remindsave(int userid, int irole, string startwork, string offwork, bool remind)
        {
            ResultEntity re = db.Crm.StoredQuery<ResultEntity>("Mb_Sp_RemindSave", new
            {
                userid,
                irole,
                startwork,
                offwork,
                remind
            }).FirstOrDefault();

            return ResultUtility.UnknownResult(re.success, re.imessage, re.imessage, re.data);
        }

        /// <summary>
        /// 库存上报列表
        /// url: /scrm/app/sbkclist
        /// </summary>
        [HttpGet]
        public string sbkclist(int userid, int irole, int beginid, string usecode)
        {
            List<dynamic> list = db.Crm.StoredQuery<dynamic>("Mb_Sp_SbkcList", new
            {
                userid,
                irole,
                beginid,
                usecode
            }).ToList();

            return ResultUtility.SuccessResult(data: list);
        }

        /// <summary>
        /// 公用参数--带出上报月份
        /// url: /scrm/app/syssetting
        /// </summary>
        [HttpGet]
        public string syssetting(string tag)
        {
            List<dynamic> list = db.Crm.StoredQuery<dynamic>("Mb_sp_Setting", new
            {
                tag
            }).ToList();

            return ResultUtility.SuccessResult(data: list);
        }

        /// <summary>
        /// 点确定时新增上报库存
        /// url: /scrm/app/sbkcnew
        /// </summary>
        [HttpPost]
        public string sbkcnew(int userid, int irole, int keyid, string usecode, string name, string openmonth)
        {
            ResultEntity re = db.Crm.StoredQuery<ResultEntity>("Mb_Sp_SbkcNew", new
            {
                userid,
                irole,
                keyid,
                usecode,
                name,
                openmonth
            }).FirstOrDefault();

            return ResultUtility.UnknownResult(re.success, re.imessage, re.imessage, re.data);
        }

        /// <summary>
        /// 库存上报提交
        /// url: /scrm/app/submitsbkc
        /// </summary>
        [HttpPost]
        public string submitsbkc(int userid, int irole, string code, string id, string bigqnty, string smallqnty)
        {
            ResultEntity re = db.Crm.StoredQuery<ResultEntity>("Mb_Sp_SubmitSbkc", new
            {
                userid,
                irole,
                code,
                id,
                bigqnty,
                smallqnty
            }).FirstOrDefault();

            return ResultUtility.UnknownResult(re.success, re.imessage, re.imessage, re.data);
        }

        /// <summary>
        /// 库存上报扫码
        /// url: /scrm/app/sbkcscancode
        /// </summary>
        [HttpPost]
        public string sbkcscancode(int userid, int irole, string code, string wlm)
        {
            var re = db.Crm.StoredQuery<dynamic>("Mb_Sp_SbkcScancode", new
            {
                userid,
                irole,
                code,
                wlm
            }).FirstOrDefault();

            return ResultUtility.UnknownResult(re.success, re.imessage, re.imessage, data: re);
        }

        /// <summary>
        /// 获取当前库存上报统计信息
        /// url: /scrm/app/sbkcinfo
        /// </summary>
        [HttpGet]
        public string sbkcinfo(int userid, int irole, string code)
        {
            List<dynamic> list = db.Crm.StoredQuery<dynamic>("Mb_Sp_SbkcInfo", new
            {
                userid,
                irole,
                code
            }).ToList();

            return ResultUtility.SuccessResult(data: list);
        }

        /// <summary>
        /// 获取当前库存上报产品物流码信息
        /// url: /scrm/app/sbkcwlminfo
        /// </summary>
        [HttpGet]
        public string sbkcwlminfo(int userid, int irole, string code)
        {
            List<dynamic> list = db.Crm.StoredQuery<dynamic>("Mb_Sp_SbkcwlmInfo", new
            {
                userid,
                irole,
                code
            }).ToList();

            return ResultUtility.SuccessResult(data: list);
        }

        /// <summary>
        /// 库存上报完成
        /// url: /scrm/app/sbkcfinish
        /// </summary>
        [HttpPost]
        public string sbkcfinish(int userid, int irole, string code)
        {
            ResultEntity re = db.Crm.StoredQuery<ResultEntity>("Mb_Sp_Sbkcfinish", new
            {
                userid,
                irole,
                code
            }).FirstOrDefault();

            return ResultUtility.UnknownResult(re.success, re.imessage, re.imessage, re.data);
        }

        /// <summary>
        /// 导航信息
        /// url: /scrm/app/navigationinfo
        /// </summary>
        [HttpGet]
        public string navigationinfo(int keyid)
        {
            List<dynamic> list = db.Crm.StoredQuery<dynamic>("Mb_Sp_NavigationInfo", new
            {
                keyid
            }).ToList();

            return ResultUtility.SuccessResult(data: list);
        }

        /// <summary>
        /// 通过编号获取门店经销商信息New 完善信息
        /// url: /scrm/app/codedealerinfonew
        /// </summary>
        [HttpGet]
        public string codedealerinfonew(string code)
        {
            List<dynamic> list = db.Crm.StoredQuery<dynamic>("Mb_Sp_CodeDealerInfoNew", new
            {
                code
            }).ToList();

            return ResultUtility.SuccessResult(data: list);
        }

        /// <summary>
        /// 通过编号获取区域覆盖信息
        /// url: /scrm/app/codedealerareainfo
        /// </summary>
        [HttpGet]
        public string codedealerareainfo(string code)
        {
            List<dynamic> list = db.Crm.StoredQuery<dynamic>("Mb_Sp_CodeDealerAreaInfo", new
            {
                code
            }).ToList();

            return ResultUtility.SuccessResult(data: list);
        }

        /// <summary>
        /// 未读信息个数
        /// url: /scrm/app/messagecount
        /// </summary>
        [HttpGet]
        public string messagecount(int userid, int irole)
        {
            List<dynamic> list = db.Crm.StoredQuery<dynamic>("Mb_Sp_MessageCount", new
            {
                userid,
                irole
            }).ToList();

            return ResultUtility.SuccessResult(data: list);
        }
    }
}
